{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Resonator class basics\n",
    "The **`resonator class`** can be used to **fit resonator measurements** (or fit live during the measurement, see the spectroscopy example notebook for that).<br>\n",
    "The `resonator class` is able to **fit the (squared) amplitude or complex scattering data** to multiple fit models. Currently it is possible to fit the data to a **Lorentzian curve, skewed Lorentzian curve, Fano resonance curve, and a circle fit**.<br>\n",
    "All fit parameters are saved in the hdf5 file and comparison views between data and fit are created.\n",
    "\n",
    "More information about the background to the fit models can be found i.e. in the papers by P. J. Petersan, [J. Appl. Phys **84** (1998)](https://aip.scitation.org/doi/10.1063/1.368498) and S. Probst, [Rev. Sci. Instrum. **86** (2015)](https://aip.scitation.org/doi/10.1063/1.4907935)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "## start qkit and import the necessary classes; here we assume a already configured qkit environment \n",
    "import qkit\n",
    "qkit.start()\n",
    "\n",
    "from qkit.analysis.resonator import Resonator"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "A **`resonator object`** takes the path of the data file as an argument (mandatory). The path can be retrieved by using the file UUID and `qkit`'s file information database."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "r = Resonator(qkit.fid.measure_db['XXXXXX'])"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The fitting is done by **calling one of the fit functions** of the object. It is asumend, that the datasets for **amplitude and phase** are propperly named. Fitting all entries of a **value matrix** dataset requires an additional **parameter `fit_all = True`**. Fitting a value box is not yet possible.<br>\n",
    "The **circle fit** algorithm takes the resonator type into account by chosing **either `reflection = True` or `notch = True` (default)**.<br>\n",
    "The **frequency range of the fit can be set** to only fit the data within that range. By default all frequency points contribute to the fit."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "r.fit_lorentzian(f_min = 5.0e9) ## set lower frequency boundary\n",
    "r.fit_skewed_lorentzian(f_min = 5.2e9, f_max = 5.6e9) ## set frequency range\n",
    "r.fit_fano(fit_all = True) ## fit all entries of a value matrix\n",
    "r.fit_circle(reflection = True, fit_all = True) ## reflection resonator; fit all entries of a value matrix"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 2",
   "language": "python",
   "name": "python2"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.15"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
